<header id="topbar">
    <div class="topbar-left">
        <ol class="breadcrumb">
            <li class="crumb-active">
                <a href="#stats/order/">订单列表</a>
            </li>
        </ol>
    </div>
    <div class="topbar-right">
        <div class="ml15 ib va-m" id="toggle_sidemenu_r">
            <a href="#" class="pl5"> <i class="fa fa-sign-in fs22 text-primary"></i>
            </a>
        </div>
    </div>
</header>

<section id="content" class="animated fadeIn">
    <div class="panel overflow">
        <table class="table table-striped fs13" id="main-list">
            <thead>
            <tr class="bg-light">
                <th class="sortable" data-field="id">Index ID</th>
                <th>订单id</th>
                <th>用户id</th>
                <th>彩种</th>
                <th>玩法</th>
                <th>期号</th>
                <th>购买号码</th>
                <th class="sortable" data-field="price">购买金额</th>
                <th class="sortable" data-field="win_price">中奖金额</th>
                <th class="sortable" data-field="bonus">加奖金额</th>
                <th>返奖率</th>
                <th class="sortable" data-field="status">状态</th>
                <th>购买时间</th>
                <th class="sortable" data-field="updated_at">最后更新时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody class="admin-form">

            <% var moment = require('moment'); %>
            <%if(items.length > 0){
            _.each(items, function(item){ %>
            <tr data-id="<%= item.id %>">
                <td><%= item.id %></a></td>
                <td><%= item.order_id %></td>
                <td><a href="/#stats/account/?id=<%= item.user_id %>"><%= item.user_id %></a></td>
                <td><%= window.LOTTERY_TYPE[item.activity_type] %></td>
                <td><%= window.get_bet_name(item.activity_type, item.detail.bet_type) %></td>
                <td><%= item.detail.term %></td>
                <td style="white-space: normal; "><%= item.detail.number %></td>
                <td><%= item.detail.price %></td>
                <td><%= item.detail.win_price %></td>
                <td><%= item.detail.bonus %></td>
                <td><%= ((item.detail.win_price + item.detail.bonus) / item.detail.price * 100).toFixed(2) %>%</td>
                <td><%= window.ORDER_STATUS[item.status] %></td>
                <td><%= item.detail.created_at %></td>
                <td><%= item.detail.updated_at %></td>
                <td class="text-left">
                    <% if (item.status == 5) { %>
                    <a onclick="check_order(<%= item.id %>, 3)">审核通过</a>
                    <a onclick="check_order(<%= item.id %>, 6)">不通过</a>
                    <% } %>
                </td>
            </tr>
            <% }) %>
            <%}%>
            </tbody>
        </table>
    </div>

    <div>
        <div class="pull-left" id="page-tips"></div>
        <div id="paginator"></div>
    </div>
</section>

<!-- Start: Right Sidebar -->
<aside id="sidebar_right" class="nano">
    <div class="p20 admin-form">

        <h4 class="mt5 text-muted fw500">过滤条件：</h4>
        <hr class="short">

        <h6 class="fw400">订单状态</h6>
        <div class="section mb15">
            <label class="field select">
                <select id="searchStatus" name="searchStatus" data-field="status">
                    <option value="-1"
                    <%= searched.status == -1 ? 'selected' : '' %>>所有</option>
                    <% _.each(window.ORDER_STATUS, function(v, k){ %>
                    <option value="<%= k %>"
                    <%= searched.status == k ? 'selected' : '' %>> <%= v %> </option>
                    <% }); %>
                </select>
                <i class="arrow double"></i>
            </label>
        </div>
        <hr class="short">

        <h6 class="fw400">用户ID</h6>
        <div class="section mb15">
            <label for="searchUserID" class="field prepend-icon">
                <input type="text" title="用户ID" data-field="user_id" id="searchUserID" class="gui-input"
                       placeholder="用户ID" value="<%= searched.user_id %>">
                <label for="searchUserID" class="field-icon"><i class="fa fa-tag"></i>
                </label>
                <i class="arrow doube"></i>
        </div>

        <h6 class="fw400">彩种</h6>
        <div class="section mb15">
            <label for="searchActivityType" class="field select">
                <select id="searchActivityType" name="searchActivityType" data-field="activity_type">
                    <option value="-1">所有</option>
                    <% _.each(LOTTERY_TYPE, function(v, k){%>
                    <option value="<%= k %>"
                    <%= searched.activity_type == k ? 'selected' : '' %>> <%= v %> </option>
                    <% }) %>
                </select>
                <i class="arrow double"></i>
            </label>
            <i class="arrow doube"></i>
        </div>
        <h6 class="fw400">玩法</h6>
        <div class="section mb15">
            <label for="searchBetType" class="field select">
                <select id="searchBetType" name="searchBetType" data-field="bet_type">
                    <option value="-1">所有</option>
                    <% _.each(bet_list, function(v, k){%>
                    <option value="<%= k %>"
                    <%= searched.bet_type == k ? 'selected' : '' %>><%= v %></option>
                    <% }) %>
                </select>
                <i class="arrow double"></i>
            </label>
            <i class="arrow doube"></i>
        </div>
        <h6 class="fw400">下单时间</h6>
        <div class="section row">
            <div class="col-md-6">
                <input type="text" title="下限，包含当天" name="searchCreatedAtLower" id="searchCreatedAtLower"
                       class="gui-input" data-type="date" value="<%= searched.created_at_lower %>" placeholder=">=">
                </label>
                </label>
            </div>
            <div class="col-md-6">
                <input type="text" title="上限，不包括当天" name="searchCreatedAtUpper" id="searchCreatedAtUpper"
                       class="gui-input" data-type="date" value="<%= searched.created_at_upper %>" placeholder="<">
                </label>
                </label>
            </div>
        </div>
        <hr class="short">

        <button class="btn btn-default btn-block" type="button" id="search">搜索</button>
    </div>
</aside>
<!-- End: Right Sidebar -->
<script>
    function check_order(order_id, status) {
        if (window.confirm("确定要将该订单状态改为" + window.ORDER_STATUS[status] + '吗？')) {
            var url = '/admin/order/' + order_id + '/' + status;
            $.post(url, function (data) {
                alert("更新成功!");
            });
        }
        ;
    }

    $('#searchActivityType').on('change', function () {
        var key = $('#searchActivityType').val();
        $("#searchBetType").empty();
        var option = '<option value="-1">所有</option>';
        if (key) {
            var bet_type = window.BET_TYPE[$('#searchActivityType').val()];
            $.each(bet_type, function (key, value) {
                option += "<option value='" + key + "'>" + value + "</option>";
            });
        }
        $('#searchBetType').html(option);

    })
</script>
